package com.example.demo.model.sys.sys.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.Results.BasePage;
import com.example.demo.Results.ResultClass;
import com.example.demo.model.sys.sys.entity.SysMenu;
import com.example.demo.model.sys.sys.mapper.SysMenuDao;
import com.example.demo.model.sys.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author STAHYW
 * @since 2021-09-29
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenu> implements SysMenuService {

    @Autowired
    SysMenuDao sysMenuDao;
    
    @Override
    public ModelAndView getMenuList(Integer pageNo, Integer pageSize) {
        ModelAndView modelAndView = new ModelAndView();
        Page page = BasePage.getPage(pageNo, pageSize);
        IPage menuPage = sysMenuDao.selectPage(page, null);
        modelAndView.addObject("menuPage", menuPage);

        modelAndView.setViewName("/sys/menuList");

        return modelAndView;
        
    }

    @Override
    public ModelAndView menuEdit(Integer id) {
        ModelAndView modelAndView = new ModelAndView();

        List<SysMenu> sysMenusList = sysMenuDao.selectList(null);
        modelAndView.addObject("sysMenusList", sysMenusList);
        SysMenu sysMenu = sysMenuDao.selectById(id);
        modelAndView.addObject("sysMenu", sysMenu);
        modelAndView.setViewName("/sys/menuEdit");
        return modelAndView;
        


    }

    @Override
    public ResultClass menuEditDo(SysMenu sysMenu) {

        sysMenuDao.updateById(sysMenu);

        return ResultClass.ok("操作成功！");

    }


}
